using System.ComponentModel;
using System.Xml.Linq;
using UnityEngine;

public class PipeSpawner : MonoBehaviour
{
    public GameObject pipePairPrefab;
    public float spawnRate = 2f;// 生成间隔时间(秒)
    public float heightVariation = 2f;// 管道高度变化范围
    public GameObject container;

    private float timer = 0f;

    void Update()
    {
        if (timer >= spawnRate)
        {
            SpawnPipe();
            timer = 0f;
        }
        else
        {
            timer += Time.deltaTime;
        }
    }

    void SpawnPipe()
    {
        Vector3 spawnPos = transform.position + new Vector3(0, Random.Range(-heightVariation, heightVariation), 0);
        Instantiate(pipePairPrefab, spawnPos, Quaternion.identity, container.transform);

    }
}